import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'

export function getCookieToken() {
  return Cookies.get(TokenKey)
}

export function setCookieToken(token: any) {
  return Cookies.set(TokenKey, token)
}

export function removeCookieToken() {
  return Cookies.remove(TokenKey)
}

export function getCookieProblem(type: any) {
  if (!['soft', 'hard'].includes(type)) return null
  const key = type === 'soft' ? 'softProblemCookie' : 'hardProblemCookie'
  const content = localStorage.getItem(key)
  if (!content) return null
  try {
    return JSON.parse(content)
  } catch {
    return null
  }
}

export function setCookieProblem(type: any, content: any) {
  if (!['soft', 'hard'].includes(type)) return null
  const key = type === 'soft' ? 'softProblemCookie' : 'hardProblemCookie'
  localStorage.setItem(key, JSON.stringify(content))
}
